// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {CreditRecord,CreditRecordList} from '../domains/creditrecord.domain';
// import {CreditRecord} from '../domains/creditrecord.domain';

/**
 * 
 */
@Injectable({
  providedIn: 'root'
})
export class CreditRecordServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'creditRecordServiceSvr.assx/';
  }

  
  listCreditRecord(token: string, customerId: string, skip: number, size: number): Promise<CreditRecordList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<CreditRecordList>(this.baseUrl + 'listCreditRecord', httpParams).then((res) => {
      return new CreditRecordList(res);
    });
  }

  
  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }

  
  getCreditRecord(token: string, id: string): Promise<CreditRecord> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString());
    return this.request.post<CreditRecord>(this.baseUrl + 'getCreditRecord', httpParams).then((res) => {
      return new CreditRecord(res);
    });
  }

  
  saveCreditRecord(token: string, customerId: string, creditRuleId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('creditRuleId', creditRuleId.toString());
    return this.request.post<number>(this.baseUrl + 'saveCreditRecord', httpParams).then((res) => {
      return res;
    });
  }
}
